<template>
    <view class="invitefriend">
        <view class="yqm">
            {{yaoqingm}}           
        </view>
        <view class="clickfhz" @click="copy">点击复制</view>
        <view class="qrcid">
            <image :src="qrimg"></image>
        </view>
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    import qr from "../../static/wxqrcode.js";
    export default {
        data() {
            return {
                yaoqingm: '',
                qrimg: '',
            }
        },
        onLoad() {
            uinfo = uni.getStorageSync('userInfo');
            this.yaoqingm = uinfo.userId;
            this.pagmg();
        },
        onPullDownRefresh() {
            console.log('refresh');
        
            this.pagmg();
        },
        methods: {
            pagmg() {
                request.postAssets('/assets/userWallet/queryDataDictionary', {
                    key: "invite_url"
                }).then(res => {
                    
                    if (res.code == '200') {
                        uni.stopPullDownRefresh();
                        let urls=res.data.value+'?userId='+uinfo.userId;
                        let img = qr.createQrCodeImg(urls, {
                            size: parseInt(300)
                        })
                        this.qrimg = img;
                    }else{
                        uni.stopPullDownRefresh();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
            //一键复制
            copy() {

                // #ifdef H5
                this.$copyText(uinfo.userId).then(
                    res => {
                        uni.showToast({
                            title: '复制成功'
                        })
                    }
                )
                // #endif
                // #ifndef H5
                uni.setClipboardData({
                    data: uinfo.userId,
                    success: () => {
                        uni.showToast({
                            title: '复制成功'
                        })
                    }
                })
                // #endif

            },
            //保存图片
            down() {
                // #ifdef H5
                    uni.showToast({
                        title: '网页端请截屏保存',
                        icon:"none"
                    })
                // #endif
                // #ifndef H5
                
                uni.downloadFile({ //下载
                    url: this.qrimg, //图片下载地址
                    success: res => {
                        if (res.statusCode === 200) {
                            uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
                                filePath: res.tempFilePath, //图片文件路径
                                success: function() {
                                    uni.showToast({
                                        title: '图片保存成功',
                                        icon: 'none',
                                    });
                                },
                                fail: function(e) {
                                    console.log(e);
                                    uni.showToast({
                                        title: '图片保存失败',
                                        icon: 'none',
                                    });
                                }
                            });
                        }
                    }
                });
                // #endif
            },
        }
    }
</script>

<style>
    .invitefriend {
        width: 750rpx;
        height: 1334rpx;
        background: url('../../static/img/aiv.png') no-repeat;
        background-size: 100%;
        padding: 1rpx 0 0 0;
    }
    
    /* #ifndef APP-PLUS */
    .yqm {
        color: #FFFFFF;
        display: flex;
        justify-content: center;
        margin: 210px 0 0 0;
        font-size: 60px;
        color: #000000;
        font-weight: 600;
        align-items: center;
    }
    /* #endif */
    /* #ifdef APP-PLUS */
    .yqm {
        color: #FFFFFF;
        display: flex;
        justify-content: center;
        margin: 360rpx 0 0 0;
        font-size: 60px;
        color: #000000;
        font-weight: 600;
        align-items: center;
    }
    /* #endif */
    /* #ifndef APP-PLUS */
    .clickfhz{
        width: 230rpx;
        height: 66rpx;
        line-height: 66rpx;
        font-size: 26rpx;
        border-radius: 10px;
        text-align: center;
        background: #0E68D7;
        color: #FFFFFF;
        margin: 16px auto 76px;
    }
    /* #endif */
    /* #ifdef APP-PLUS */
    .clickfhz{
        width: 230rpx;
        height: 66rpx;
        line-height: 66rpx;
        font-size: 26rpx;
        border-radius: 10px;
        text-align: center;
        background: #0E68D7;
        color: #FFFFFF;
        margin: 28rpx auto 130rpx;
    }
    /* #endif */
    .qrcid {
        display: flex;
        justify-content: center;
        margin: 66rpx 0 0 0;
    }

    .qrcid image {
        width: 320rpx;
        height: 320rpx;
        background: #F5F5F5;
        border-radius: 10px;
    }

    .btnid {
        display: flex;
        justify-content: center;
        margin: 38rpx 0 0 0;
    }

    .btnid view {
        width: 74px;
        height: 26px;
        background-color: #91EBFF;
        font-size: 14px;
        text-align: center;
        line-height: 26px;
        border-radius: 16px;
    }
    
    .downs{
        width: 200rpx;
        height: 60rpx;
        background-color: #0E68D7;
        margin: 20rpx auto 0;
        font-size: 30rpx;
        color: #FFFFFF;
        text-align: center;
        line-height: 60rpx;
        border-radius: 10rpx;
    }
</style>
